package codetop.microsoft.T142;

import util.ListNode;
import util.ListUtil;

/**
 * @Author: 18362
 * @Create: 2022-08-14 11:20:24 星期日
 */
public class M142 {
    public static void main(String[] args) {
        ListNode head = ListUtil.parseListNode("[3,2,0,-4]");
        int pos = 2;
        ListNode tail = head;
        while (tail.next != null)
            tail = tail.next;
        ListNode p = head;
        for (int i=0; i<pos; ++i)
            p = p.next;
        tail.next = p;
        ListNode node = new Solution().detectCycle(head);
        System.out.println(node == p);
        System.out.println(node.val);
    }
}
